<template>
	<view>
		<view class="page-section page-section-gap">
			<br>
			{{info}}
			<map style="width: 100%;height: 300px;" :latitude="latitude"
			:longitude="longitude" :markers="covers"></map>
			<u-button type="success" @click="refresh">刷新</u-button>
		</view>
		<view>
			<u-toast ref="uToast"/>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info:"当前位置",
				id:0,
				title:'map',
				latitude:39.909,
				longitude:116.39742,
				covers:[{
					latitude:39.909,
					longitude:116.49742,
					iconPath:'../../static/user/png'
				}]
			}
		},
		onLoad() {
			uni.getLocation({
				type:'gcj02',
				success:(res)=>{
					this.$refs.uToast.show({
						title:res.longitude+' '+res.latitude,
						type:'success'
					})
					this.latitude = res.latitude;
					this.longitude = res.longitude;
					this.covers[0].latitude = res.latitude;
					this.covers[0].longitude = res.longitude;
					this.info = "当前位置" + this.latitude + " " + this.longitude;
				}
			});
		},
		methods: {
			refresh(){
				uni.getLocation({
					type:'gcj02',
					success:(res)=>{
						this.$refs.uToast.show({
							title:res.longitude+' '+res.latitude,
							type:'success'
						})
						this.latitude = res.latitude;
						this.longitude = res.longitude;
						this.covers[0].latitude = res.latitude;
						this.covers[0].longitude = res.longitude;
						this.info = "当前位置" + this.latitude + " " + this.longitude;
					}
				});
			}
		}
	}
</script>

<style>

</style>
